package com.iflytek.management.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;


import com.iflytek.management.pojo.SysUser;

public interface SysUserMapper {
	
	//通过id删除人员（假删除）
	@Update("update  sys_user set isdelete=1 where userid=#{userid}")
	int deleteByPrimaryKey(Integer userid)throws Exception;
	
	//添加新人员（默认密码123）
	@Insert("insert into sys_user (name, username, password, company, email, phone, department, roleid, isdelete )"
			+ "values (#{name}, #{username}, 123, #{company}, #{email}, #{phone}, #{department}, #{roleid},0)")
    int insert(SysUser user)throws Exception;
	
	//通过id修改pic（改头像）
	@Update("update  sys_user  set pic=#{pic} where userid=#{userid}")
    int updatePicByPrimaryKey(Integer userid)throws Exception;
	
	//重置密码 默认123
	@Update("update  sys_user  set password=123 where userid=#{userid} ")
	int updatePwdByUserid(Integer userid)throws Exception;
	
	//通过id修改个人信息（员工只能修改自己姓名，电话，邮箱）
	@Update("update  sys_user  set name=#{name}, email=#{email}, phone=#{phone} where userid=#{userid}")
	int updatePersonById(SysUser user)throws Exception;
	
	//通过id修改个人信息（项目经理修改姓名，电话，邮箱， 职位）
	@Update("update  sys_user  set name=#{name}, email=#{email}, phone=#{phone}, roleid=#{roleid} where userid=#{userid}")
	int updatePersonByIdManager(SysUser user)throws Exception;
	
	//通过id修改人员信息（不包括头像）
	@Update("update  sys_user  set userid=#{userid}, name=#{name}, username=#{username}, password=#{password}, company=#{company},"
			+ "email=#{email}, phone=#{phone}, title=#{title},department=#{department}, roleid=#{roleid} where userid=#{userid}")
	int updateByPrimaryKey(Integer userid)throws Exception;
	
	//通过id查询员工信息
    @Select("select * from sys_user where userid=#{userid} and isdelete=0")
    SysUser selectByPrimaryKey(Integer userid)throws Exception;
    
    //查询全部员工信息
    @Select("select * from sys_user where isdelete=0")
    List<SysUser> selectAll()throws Exception;
    
    @Select("select * from sys_user su,project_user_role pur where su.userid=pur.userid and pur.proid=#{proid}")
    List<SysUser> findByProid(int proid);

}